/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin		 	*/
/*	Project:	GoLib-1.0.0			*/
/*	Author:		gong_libin			*/
/*	Date:		2016_01_01			*/
/*	File:		GoIdx.go			*/
/********************************************************/

package GoCls

import (
	"hash"
	"bytes"
	"unsafe"
	"crypto/md5"
	"crypto/sha1"
	"encoding/binary"
)

var __ui32 int32
var __ui64 int64

const (
	GO_IX_UI32	int = int(unsafe.Sizeof(__ui32))
	GO_IX_UI64	int = int(unsafe.Sizeof(__ui64))
)

func GoIdxUint32(s []byte) uint32 {
	var r, t uint32
	for i := 0; i < len(s); i += GO_IX_UI32 {
		b := bytes.NewBuffer(s[i : i + GO_IX_UI32])
		binary.Read(b, binary.BigEndian, &t)
		r ^= t
	}
	return r
}

func GoIdxUint64(s []byte) uint64 {
	var r, t uint64
	for i := 0; i < len(s); i += GO_IX_UI64 {
		b := bytes.NewBuffer(s[i : i + GO_IX_UI64])
		binary.Read(b, binary.BigEndian, &t)
		r ^= t
	}
	return r
}

/* md5 */
type GoMd5 struct {
	md5	hash.Hash
}

func (m *GoMd5) GoMd5Sum(s []byte) (d []byte) {
	m.md5 = md5.New()
	m.md5.Write([]byte(s))
	return m.md5.Sum([]byte(""))
}

/* sha1 */
type GoSha struct {
	sha	hash.Hash
}

func (h *GoSha) GoShaSum(s []byte) (d []byte) {
	h.sha = sha1.New()
	h.sha.Write([]byte(s))
	return h.sha.Sum([]byte(""))
}
